<?php declare(strict_types=1);


namespace Database\Migration;

use Swoft\Db\Schema\Blueprint;
use Swoft\Devtool\Annotation\Mapping\Migration;
use Swoft\Devtool\Migration\Migration as BaseMigration;

/**
 * Class Organization
 *
 * @since 2.0
 *
 * @Migration(time=20200506084306)
 */
class Organization extends BaseMigration
{
    /**
     * @return void
     */
    public function up(): void
    {
        //开始编写
        $this->schema->createIfNotExists('organization', function (Blueprint $blueprint){
            $blueprint->comment('组织架构表');

            $blueprint->increments('id')->comment('主键id');
            $blueprint->string('item_id', 32)->index('item_id_index')->comment('数据唯一ID');
            //开始自己数据字段
            $blueprint->string('name', 64)->comment('组织名称');
            $blueprint->string('permission_value', 64)->comment('组织唯一值（供开发者读取），同一个权限系统内唯一，最长64个字符，不可为空');
            $blueprint->string('role_id', 32)->comment('角色id');
            $blueprint->tinyInteger('frozen_state')->nullable()->default(0)->comment('是否冻结：0未冻结 1已冻结');
            $blueprint->integer('created_at')->comment('创建时间 int');
            $blueprint->integer('updated_at')->nullable()->default(0)->comment('更新时间 int');
            //结束自己数据字段
            $blueprint->engine = 'Innodb';
            $blueprint->charset = 'utf8mb4';
        });

    }

    /**
     * @return void
     */
    public function down(): void
    {
        $this->schema->dropIfExists('organization');
    }
}
